﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.SpecialUtils.Html;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using static ArticleContentCreate.WebSite.WebSiteStaticvlaue;

namespace ArticleContentCreate.WebSite.Pixiv.PixivArt
{
    internal class PArtHelper
    {
        /// <summary>
        /// 获取作者信息
        /// </summary>
        /// <param name="ArticleId"></param>
        /// <returns></returns>
        public ArticleInfo GetArticleInfo(string ArticleId)
        {
            string Api = "https://www.pixiv.net/member.php?id=" + ArticleId;
            String Shtml = WebHelper.MobileGet(Api);
            ArticleInfo info = new ArticleInfo();
            info.Title = string.Format("【P站画师】{0}（ID：{1}）", HtmlHelper.GetFirstText(Shtml, "//p[@class='profile-user-name']"), ArticleId);

            foreach (String Line in HtmlHelper.GetHtmlValueList(Shtml, "//table[@class='collapsed-hidden']//tr"))
            {
                info.Content += string.Format("{0}：{1}\r\n", HtmlHelper.GetFirstText(Line, "//td[1]"), HtmlHelper.GetFirstText(Line, "//td[2]"));
            }
            return info;
        }

        /// <summary>
        /// 获取文件数据ID
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public string GetArtId(string FilePath)
        {
            string Filepath = FileNameHelper.GetFileNameWithoutExtension(FilePath);

            return TextHelper.RegexText(FilePath, "[0-9]{1,}");
        }
    }
}